﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace NNDC
{
    public partial class Main : Form
    {
        public Main()
        {
            
            InitializeComponent();
            this.skinEngine1.SkinFile = "OneOrange.ssk";
        }
        public SqlDataReader sdr;
        public string power;
        public string Names;
        public string Times;

        private void Main_Load(object sender, EventArgs e)
        {
            switch (power)
            {
                case "1": txtpower.Text = "超级管理员"; break;
                case "2": txtpower.Text = "经理"; break;
                case "3": txtpower.Text = "服务员"; break;
            }
            txtName.Text = Names;
            txtDate.Text = Times;
            if (power == "3")
            {
                基础信息ToolStripMenuItem.Enabled = false;
                系统维护ToolStripMenuItem.Enabled = false;
            }
            if (power == "2")
            {
                系统维护ToolStripMenuItem.Enabled = false;
            }
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }

        private void Main_Activated(object sender, EventArgs e)
        {
            listView1.Items.Clear();//清除list中的项
            SqlConnection conn = data.DBConn.Cycon();
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from tb_Room",conn);
            sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                string zt = sdr["RoomZT"].ToString().Trim();
                AddItems(zt);
            }
            conn.Close();
        }
        private void AddItems(string rzt)
        {
            if (rzt == "使用中")
            {
                listView1.Items.Add(sdr["RoomName"].ToString(), 1);
            }
            else
            {
                listView1.Items.Add(sdr["RoomName"].ToString(), 0);
            }
        }

        private void listView1_Click(object sender, EventArgs e)
        {
            string names = listView1.SelectedItems[0].SubItems[0].Text;
            SqlConnection conn = data.DBConn.Cycon();
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from tb_Room where RoomName='"+names+"'",conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            sdr.Read();
            string zt = sdr["RoomZT"].ToString().Trim();
            sdr.Close();
            if (zt == "使用中")
            {
                this.contextMenuStrip1.Items[0].Enabled = false;
                this.contextMenuStrip1.Items[1].Enabled = true;
                this.contextMenuStrip1.Items[3].Enabled = true;
                this.contextMenuStrip1.Items[5].Enabled = true;
                this.contextMenuStrip1.Items[6].Enabled = true;
            }
            if (zt == "待用")
            {
                this.contextMenuStrip1.Items[0].Enabled = true;
                this.contextMenuStrip1.Items[1].Enabled = false;
                this.contextMenuStrip1.Items[3].Enabled = false;
                this.contextMenuStrip1.Items[5].Enabled = false;
                this.contextMenuStrip1.Items[6].Enabled = false;
            }
            conn.Close();
        }

        private void 开台ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 0)
            {
                string names = listView1.SelectedItems[0].SubItems[0].Text;
                Open openRoom = new Open();
                openRoom.name = names;
                openRoom.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择桌台");
            }
        }

        private void 点加菜ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 0)
            {
                string names = listView1.SelectedItems[0].SubItems[0].Text;
                DC dc = new DC();
                dc.RName = names;
                dc.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择桌台");
            }
        }

        private void 消费信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 0)
            {
                string names = listView1.SelectedItems[0].SubItems[0].Text;
                Serch serch = new Serch();
                serch.RName = names;
                serch.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择桌台");
            }
        }

        private void 结账ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 0)
            {
                string names = listView1.SelectedItems[0].SubItems[0].Text;
                JZ jz = new JZ();
                jz.RName = names;
                jz.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择桌台");
            }
        }

        private void 取消开台ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 0)
            {
                string names = listView1.SelectedItems[0].SubItems[0].Text;
                SqlConnection conn = data.DBConn.Cycon();
                conn.Open();
                SqlCommand cmd = new SqlCommand("update tb_Room set RoomZT='待用',Num=0 where RoomName='"+names+"'",conn);
                cmd.ExecuteNonQuery();
                cmd = new SqlCommand("delete from tb_GuestFood where zhuotai='"+names+"'",conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                Main_Activated(sender,e);
            }
            else
            {
                MessageBox.Show("请选择桌台");
            }
        }

        private void 桌台信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Desk desk = new Desk();
            desk.ShowDialog();
        }

        private void 职员信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Users user = new Users();
            user.ShowDialog();
        }

        private void 权限管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QxGl qxgl = new QxGl();
            qxgl.ShowDialog();
        }

        private void 系统维护ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            BF bf = new BF();
            bf.ShowDialog();
        }

        private void 系统修复ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HF hf = new HF();
            hf.ShowDialog();
        }

        private void 口令设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Pwd pwd = new Pwd();
            pwd.names = Names;
            pwd.ShowDialog();
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About ab = new About();
            ab.ShowDialog();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定退出系统?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void 锁定系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Lock locksystem = new Lock();
            locksystem.Owner = this;
            locksystem.ShowDialog();
        }

        private void 日历ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dateClear da = new dateClear();
            da.ShowDialog();
        }

        private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc.exe");
        }

        private void 记事本ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("notepad.exe");
        }
    }
}
